package com.example.springboot.exception;

import cn.hutool.core.util.StrUtil;
import com.example.springboot.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionHandle {
//    public static final String ERROR_VIEW = "error";
    @ExceptionHandler(value = ServiceException.class)

    public Result servicExceptionError(ServiceException e)
    {
        log.error("业务异常");
        String code =e.getCode();
        if(StrUtil.isNotBlank(code))
        {
            return Result.erro(code,e.getMessage());
        }
        return Result.erro(e.getMessage(), e.getMessage());
    }
    @ExceptionHandler(value = Exception.class)

    public Result exceptionError(Exception e)
    {
        log.error("系统错误",e);
        return Result.erro("系统错误", e.getMessage());
    }

}
